from django.contrib import admin
from import_export.admin import ImportExportModelAdmin     # 实现导入导出功能模块
from book.models import Author, Book


# class TagInline(admin.TabularInline):
#     model = Author


class AuthorAdmin(ImportExportModelAdmin, admin.ModelAdmin):
    # fields = ('name', 'email', 'gender')     # 需要显示的字段
    # 定义字段以块状显示
    list_display = ('name', 'email')    # 后台表的外面显示字段
    search_fields = ('name', 'email')    # 后台添加搜索框
    list_filter = ('age',)              # 后台添加对年龄进行筛选
    ordering = ['email', ]               # 后台添加对邮箱的排序
    list_per_page = 20                   # 添加每页记录数
    fieldsets = (['Main', {
            'fields': ('name', 'email'),
        }],
                    ['Advanced', {
                        # 'classes': ('collapse',),      # 设置字段为折叠状态
                        'fields': ('age', 'gender'),
                    }]
        )


# 书籍表关联作者表
# class BookAdmin(admin.ModelAdmin):
#     inlines = [TagInline]


admin.site.register(Author, AuthorAdmin)
# admin.site.register(Book, BookAdmin)
admin.site.register([Book])    # 注册表到后台
